*Note: This code estimates the summary statistics reported in Table A.23 of the Supplemntal Appendix.
*	It then generates the Likelihood Ratio (LR) test quantities that are reported in Table A.24.
*	To do so, it reads-in the Stata .dta file "MainMalariaDataset.dta" and then prints relevant table output to screen.

*clear Stata
clear
clear matrix
set more off

*set working directory
cd  ""

*start log file
log using "Tables_A23_to_A24", replace

*read-in monadic data
use "MonMalariaDataset.dta"

*xtset data
sort cowcode_2 year5
xtset cowcode_2 year5

*generate output for Table A.23
summarize dr_1_at_2_m, detail

********************************************************************************************************
**Print log-likelihoods to screen for each Negative Binomial model (needed for LR tests further below)**
********************************************************************************************************

*Malaria only model
nbreg dr_1_at_2_m 
estat ic

*Pooled model
nbreg dr_1_at_2_m Lmalaria_interp_2_m Lcid_per_trop_2_m Llog_trade_m  Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m Llog_distance_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
estat ic

*Pooled (clustered se's) model
nbreg dr_1_at_2_m Lmalaria_interp_2_m Lcid_per_trop_2_m Llog_trade_m  Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m Llog_distance_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12, cluster(cowcode_2)
estat ic

*Receiver fixed effects model
xtnbreg dr_1_at_2_m Lmalaria_interp_2_m Llog_trade_m Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12, fe
estat ic

*Receiver random effects model
xtnbreg dr_1_at_2_m Lmalaria_interp_2_m Lcid_per_trop_2_m Llog_trade_m Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m Llog_distance_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12, i(cowcode_2)
estat ic

**********************************************************************************************
**Print log-likelihoods to screen for each Poisson model (needed for LR tests further below)**
**********************************************************************************************

*Malaria only model
poisson dr_1_at_2_m 
estat ic

*Pooled model
poisson dr_1_at_2_m Lmalaria_interp_2_m Lcid_per_trop_2_m Llog_trade_m  Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m Llog_distance_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
estat ic

*Pooled (clustered se's) model
poisson dr_1_at_2_m Lmalaria_interp_2_m Lcid_per_trop_2_m Llog_trade_m  Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m Llog_distance_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12, cluster(cowcode_2)
estat ic

*Receiver fixed effects model
xtpoisson dr_1_at_2_m Lmalaria_interp_2_m Llog_trade_m Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12, fe
estat ic

*Receiver random effects model
xtpoisson dr_1_at_2_m Lmalaria_interp_2_m Lcid_per_trop_2_m Llog_trade_m Llog_gdppc_2_m Lln_cinc_2_m Ldemocracy_2_m Llog_distance_m t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12, i(cowcode_2)
estat ic

**************
**Table A.24**
**************

*LR test statistics Malaria only model
di chi2tail(1, -2*(-15012.691--6118.7462 ))
*calculate the likelihood ratio test statistic
di "chi2(1) = " -2*(-15012.691--6118.7462 )

*LR test statistics Pooled model
di chi2tail(1, -2*(-4875.219  --4234.072))
*calculate the likelihood ratio test statistic
di "chi2(1) = " -2*(-4875.219  --4234.072)

*LR test statistics Pooled (clustered se's) model
di chi2tail(1, -2*(-4875.219 --4234.072))
*calculate the likelihood ratio test statistic
di "chi2(1) = " -2*(-4875.219 --4234.072)

*LR test statistics Receiver fixed effects model
di chi2tail(1, -2*( -3420.155 --3275.997))
*calculate the likelihood ratio test statistic
di "chi2(1) = " -2*( -3420.155  --3275.997 )

*LR test statistics Receiver random effects model
di chi2tail(1, -2*(-4202.247  --4053.3419 ))
*calculate the likelihood ratio test statistic
di "chi2(1) = " -2*(-4202.247  --4053.3419)

*close log file
log close
